var header_text_1 = "请选择您要 <span style='color:red;'>出售</span> 的商品类型";
var header_text_2 = "请选择您要 <span style='color:red;'>收购</span> 的商品类型";
var header_text_3 = "请选择您发布的  <span style='color:red;'>招聘</span> 信息的类型"

var purchase$sold_type = {
	'电脑硬件:' : [ "CPU", "内存条", "硬盘", "主板", "显卡", "显示器", "整套电脑", "其他电脑硬件" ],
	'旧书:' : [ "杂志", "公共课书籍", "专业课书籍", "外语书籍", "其他旧书" ],
	'日常用品:' : [ "日常用品", "电器", "穿着服饰", "其他日常用品" ],
	'手机:' : [ "Nokia", "Sony Errision", "三星", "Android", "iphone", "其他牌子" ],
	'其他:' : [ '其他' ]
};

var zp_type = {
	'兼职:' : [ "校园兼职", "校外兼职" ],
	'招聘:' : [ "校园招聘", "全国招聘", "其他招聘" ]
}

function getShowObject() {
	var value = $("#result").attr("value");
	if($(".selected-result-span").text() == "") return "";
	if(value == "0") {
		return $(".second-step");
	}
	if(value == "1") {
		return $(".second-step2");
	}
	if(value == "2") {
		return $(".zp-step");
	}
	return "";
}


function showTypeText(type) {
	$(".list-items").empty();
	$(".list-items").append(function() {
		var dl = $("<dl></dl>");
		$.each(type, function(key, value) {
			dl.append($("<dt>" + key + "</dt>"));
			dl.append($("<dd></dd>").append(function() {
					var ul = $("<ul></ul>");
					$.each(value, function(key2, value2) {
						ul.append($("<li><a href='#'>" + value2 + "</a></li>"));
					});
					return ul;
			}));
		});
		return dl;
		
	});

	
	$(".to-next, .selected-result").show();
	$(".list-items li  a").bind("click", function() {
		$(".selected-result-span").empty();
		$(".selected-result-span").append($(this).text());
		$(".selected-result-td").empty();
		$(".selected-result-td").append($(this).text());
		return false;
	});
	$(".selected-result-span").empty();
	$("#selector").show(500);
}



$(function() {
	$("#step1-radio").buttonset();
	
	$("button:not(.unbutton)").button();

	$("#radio1").bind("click", function() {
		$("#selector input, #selector .button").hide();
		$("#selector").hide("500", function() {
			$("#selector .sheader").empty();
			$("#selector .sheader").append(header_text_1);
			showTypeText(purchase$sold_type);

			$(".deal-type").empty();
			$(".deal-type").append("出售");
			$("#selector").show(500);
		});
		$("#result").attr("value", 0);
	});

	$("#radio2").bind("click", function() {
		$("#selector input, #selector .button").hide();
		$("#selector").hide("500", function() {
			$("#selector .sheader").empty();
			$("#selector .sheader").append(header_text_2);
			showTypeText(purchase$sold_type);
			$(".deal-type").empty();
			$(".deal-type").append("收购");
			$("#selector").show(500);
		});
		$("#result").attr("value", 1);
	});

	$("#radio3").bind("click", function() {
		$("#selector input, #selector .button").hide();
		$("#selector").hide("500", function() {
			$("#selector .sheader").empty();
			$("#selector .sheader").append(header_text_3);
			showTypeText(zp_type);

			$(".deal-type").empty();
			$(".deal-type").append("招聘");
			$("#selector").show(500);
		});
		$("#result").attr("value", 2);
	});
	

	$( "#datepicker, #datepicker2" ).datepicker({
		"dateFormat":"yy-mm-dd" , 
		minDate: 0, 
		changeMonth: true,
		changeYear: true
	});
	$( "#datepicker, #datepicker2" ).datepicker($.datepicker.regional["zh-CN"]);

	$("#please-select-dialog").dialog({
		height: 120,
		width: 220,
		modal: true,
		hide: "explode",
		autoOpen: false
	});
	
	$(".to-next").bind("click", function() {
		var div = getShowObject();
		if(div == "") {
			$("#please-select-dialog").dialog("open");
			
			return false;
		}
		$("#step1-radio input, #step1-radio label").hide();
		$("#selector input, #selector .button").hide();
		$(".first-step").hide(800);
		div.find(".tr").removeClass("odd-tr");
		div.find(".tr:even").addClass("odd-tr");
		div.show(500);
		div.find(".button").show()
		$("#step-img").attr("src", "pub-imgs/pub2.png");
	});

	$( ".to-first" ).bind("click", function() {
		$(".second-step .button, .zp-step .button").hide();
		$(".second-step, .zp-step").hide(500);
		$(".first-step").show(500);
		setTimeout( function() { $(".first-step .button, .radio").show() } , 300);;
		$("#step-img").attr("src", "pub-imgs/pub1.png");
	});
	
	$( ".to-finished" ).bind("click", function() {
		$(".second-step .button").hide();
		$(".second-step").hide(500, function() {
			$(".zp-step .button").hide();
			$(".zp-step").hide(500);
			$("#step-img").attr("src", "pub-imgs/pub3.png");
			$(".finished-step").show(50);
		});
		
		
	});
});
